package com.dily.study.demo.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Date: 2022-08-10 星期三
 * Time: 15:15
 * Author: Dily_Su
 * Remark: 线程总结
 */
public class ThreadAll {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // 继承 Thread 创建线程启动方式
        new MyThead1().start();

        // 实现 Runnable 创建线程启动方式
        new Thread(new MyThread2());

        // 实现 Callable 创建线程启动方式
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread3());
        new Thread(futureTask).start();
        // 获取 Callable 线程返回值
        Integer integer = futureTask.get();
        System.out.println(integer);
    }
}


// 继承 Thread 类
class MyThead1 extends Thread{
    @Override
    public void run() {
        System.out.println("继承 Thread 类创建多线程");
    }
}

// 实现 Runnable 接口
class MyThread2 implements Runnable{
    @Override
    public void run() {
        System.out.println("实现 Runnable 接口创建多线程");
    }
}

// 实现 Callable 接口
class MyThread3 implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("实现 Callable 接口创建多线程");
        return 100;
    }
}